﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.Xml.Serialization;
using System.Net.Security;
namespace RTS_WebServer
{
    class Program
    {
        public static SerializableDictionary<string,String> Configuration;
        static TcpListener TheEar = new TcpListener(IPAddress.Parse("127.0.0.1"),80);
        static TcpListener TheSafeEar = new TcpListener(IPAddress.Parse("127.0.0.1"), 443);
        static void Main(string[] args)
        {
            Configuration = new SerializableDictionary<string, string>();
            XmlSerializer[] Seri =  XmlSerializer.FromTypes(new Type[] { typeof(SerializableDictionary<string, string>) });
            XmlSerializer Confi = Seri[0];
            Configuration = (SerializableDictionary<string,string>)Confi.Deserialize(System.IO.File.Open("config.xml", System.IO.FileMode.OpenOrCreate));
            Thread HTTPThread = new Thread((ThreadStart)delegate()
            {

                TheEar.Start();
                while (true)
                {
                    while (TheEar.Pending())
                    {
                        TcpClient Wave = TheEar.AcceptTcpClient();
                        Thread Nylon = new Thread((ThreadStart)delegate() { Client.Procces(Wave); });
                        Nylon.Start();
                    }
                    Thread.Sleep(5);
                }
            });
            HTTPThread.Start();
            TheSafeEar.Start();
            while (true)
            {
                while (TheSafeEar.Pending())
                {
                    TcpClient Wave = TheSafeEar.AcceptTcpClient();
                    Thread Nylon = new Thread((ThreadStart)delegate() { Client.Procces(Wave,new SslStream(Wave.GetStream(),false),Wave.GetStream()); });
                    Nylon.Start();
                }
                Thread.Sleep(5);
            }
        }
    }
}
